package com.appspot.finajjarane.ws.rest;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.appspot.finajjarane.framework.generic.ApplicationConstants;
import com.appspot.finajjarane.framework.models.JSONModel;
import com.appspot.finajjarane.framework.models.JSONModelList;
import com.appspot.finajjarane.framework.models.TweetModel;
import com.appspot.finajjarane.framework.service.ITwitterService;
import com.sun.jersey.api.spring.Autowire;


@Component
@Scope(BeanDefinition.SCOPE_SINGLETON)
@Path("/twitter")
@Autowire
public class WSTwitter {

	@Autowired
	private ITwitterService iTwitterService;


	@GET
	@Path("/latest")
	@Produces(MediaType.APPLICATION_JSON + "; charset=UTF-8")
	public JSONModel getLatesTweets(){
		JSONModel returnedJSON;
		try {
			returnedJSON = new JSONModelList<TweetModel>(ApplicationConstants.JSON_STATUS_OK, iTwitterService.getTweetsInHomeTimeline());
		}
		catch (Exception e) {
			String message = e.getLocalizedMessage();
			returnedJSON = JSONModel.exceptionJSONModel(message);
		}
		return returnedJSON;
	}
}